//FYI: https://github.com/Tencent/puerts/blob/master/doc/unity/manual.md
import Utils from "./Utils";
import { FairyEditor, System } from "csharp";

let menu: FairyEditor.Component.IMenu = FairyEditor.App.menu.GetSubMenu("tool");
FairyEditor.App.add_onProjectOpened(() => {
  let projectPluginFolder = FairyEditor.App.pluginManager.projectPluginFolder;
  let ClearDuplicatePicturesPlugin = System.IO.Path.Combine(
    projectPluginFolder,
    "ClearDuplicatePictures",
    "dist",
    "Utils.js"
  );
  console.log(ClearDuplicatePicturesPlugin);
  let infoStr: string =
    "请修改:" +
    ClearDuplicatePicturesPlugin +
    "中commPkgName,根据实际项目的公共包名字,然后到顶部工具执行'清除重复图片'按钮";
  FairyEditor.App.Alert(infoStr);

  if (menu != null) {
    menu.AddSeperator();
    menu.AddItem(
      "清除重复图片",
      "ClearDuplicatePictures",
      function (str): void {
        FairyEditor.App.consoleView.Clear();
        Utils.findAndCalMd5();
        Utils.showRepeatPicInfoAndDeal();

        //测试案例
        // Utils.testCalMd5();
        // Utils.testMovePackItem();
      }
    );
  } else {
    console.error("找不到菜单！！！");
  }
});

FairyEditor.App.add_onProjectClosed(() => {
  if (menu != null) {
    menu.RemoveItem("ClearDuplicatePictures");
  }
});
